<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Enclosure;

/**
 * EnclosureSearch represents the model behind the search form about `common\models\Enclosure`.
 */
class EnclosureSearch extends Enclosure
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['xa_article_id', 'xa_type','xa_name', 'xa_title', 'xa_abstract', 'xa_create_time', 'xa_update_time', 'xa_remark'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Enclosure::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
        ]);

        $query->andFilterWhere(['like', 'xa_article_id', $this->xa_article_id])
            ->andFilterWhere(['like', 'xa_type', $this->xa_type])
            ->andFilterWhere(['like', 'xa_type', $this->xa_name ])
            ->andFilterWhere(['like', 'xa_title', $this->xa_title])
            ->andFilterWhere(['like', 'xa_abstract', $this->xa_abstract])
            ->andFilterWhere(['like', 'xa_create_time', $this->xa_create_time])
            ->andFilterWhere(['like', 'xa_update_time', $this->xa_update_time])
            ->andFilterWhere(['like', 'xa_remark', $this->xa_remark]);

        return $dataProvider;
    }
}
